package com.demo2do.fms.admin.dao.business;

import java.util.Date;
import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.business.shipment.DispatchOrder;

/**
 * 
 * @author Ysy
 */
@Dao("hibernate")
public interface DispatchOrderDao {
    
    /**
     * @param ids
     * @return
     */
    @Query("FROM DispatchOrder WHERE disabled = false AND id IN (:ids)")
    public List<DispatchOrder> list(@Variable("ids") List<Long> ids);
    
    /**
     * @param ids
     * @return
     */
    @Query("FROM DispatchOrder WHERE disabled = false AND id IN (:ids) ORDER BY leavingTime ASC")
    public List<DispatchOrder> listByLeavingTime(@Variable("ids") List<Long> ids);
    
    /**
     * load dispatch_order by load_group_number
     * 
     * @param loadGroupNumber
     * @return
     */
    @Query("FROM DispatchOrder WHERE disabled = false AND shipmentGroupId = :loadGroupNumber")
    public DispatchOrder loadByLoadGroupNumber(@Variable("loadGroupNumber") String loadGroupNumber);
    
    /**
     * @param dispatchOrderIds
     * @param lastOperatorId
     * @param lastModifyDate
     */
    @Execute("UPDATE DispatchOrder SET lastOperatorId = :lastOperatorId, lastModifyDate = :lastModifyDate WHERE disabled = false AND id IN (:ids)")
    public void setupInternalOils(@Variable("ids") List<Long> dispatchOrderIds, @Variable("lastOperatorId") Long lastOperatorId, @Variable("lastModifyDate") Date lastModifyDate);

    /**
     * 
     * @param ids
     * @param date
     * @param operator
     * @param reimburseCode
     */
    @Execute("UPDATE DispatchOrder SET expensePrint=true, expensePrintDate = :date, expensePrintUser = :operator, reimburseCode = :reimburseCode WHERE id IN (:ids) AND disabled = false")
    public void expenseSheetExport(@Variable("ids") List<Long> ids, @Variable("date") Date date, @Variable("operator") Long operator, @Variable("reimburseCode") String reimburseCode);
    
}